<?php

class Menu extends Menu_model {

    function __construct() {
        parent::__construct();
    }
    
    public static function getMenuList(&$array_menus = array(), $filter = array()) {
        $menu = new Menu();
        if (isset ($filter['parent_id'])) {
            $menu->addWhere("id_parent = ".$filter['parent_id']);
        }
        if (isset ($filter['type'])) {
            $menu->addWhere("type = ".$filter['type']);
        }
        $menu->disabled = 0;
		$menu->orderBy('position');
        $menu->find();
        while($menu->fetchNext()) {
            $menu_array = array();
            $menu_array['ID'] = $menu->id;
            $menu_array['NAME'] = $menu->name;
            $menu_array['POSITION'] = $menu->position;
            $menu_array['LINK'] = $menu->link;
            $menu_array['SECTION'] = $menu->section;
            $menu_array['ID_PARENT'] = $menu->id_parent;
            
            if ($menu->id_parent == 0) {
                $array_menus[$menu->id]['parent'] = $menu_array;
            } else {
                $array_menus[$menu->id]['child'] = $menu_array;
            }
            $filter['parent_id'] = $menu->id;
            self::getMenuList($array_menus[$menu->id]['childs'], $filter);
		}
    }
}
